找传奇、传世资源到传世资源站!

vb 具有预览功能的图像查看器用户控件

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardImports System.IOImports System.CollectionsPublic Class ImageViewer ' private member variables Private mFolder As String Private mImageList As ArrayList Private mImagePosition As Integer Private mPreviousImage As Image Private mCurrentImage As Image Private mNextImage As Image ''' <summary> ''' Default Constructor ''' </summary> ''' <remarks></remarks> Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub ''' <summary> ''' Default load event handler ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub ImageViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' do nothing End Sub ''' <summary> ''' Open the folder browse dialog and load ''' the initial images ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click ' Label the folder browser dialog Me.folderBrowserDialog1.Description = "Select the image directory." ' disable create folder feature of folder browser Me.folderBrowserDialog1.ShowNewFolderButton = False ' display the folder browser Dim result As DialogResult = folderBrowserDialog1.ShowDialog() If result = DialogResult.OK Then ' on okay, set the image folder to the ' folder browser's selected path mFolder = folderBrowserDialog1.SelectedPath If (Not String.IsNullOrEmpty(mFolder)) Then txtImageDirectory.Text = mFolder Else ' exit if the user cancels Return End If ' initialize the image arraylist mImageList = New ArrayList() ' loop through the image directory ' and find all of the image files ' add the found files to the image ' list - add other image types if ' necessary Dim Dir As New DirectoryInfo(mFolder) Dim f As FileInfo For Each f In Dir.GetFiles("*.*") Select Case (f.Extension.ToUpper()) Case ".JPG" mImageList.Add(f.FullName) Case ".BMP" mImageList.Add(f.FullName) Case ".GIF" mImageList.Add(f.FullName) Case Else ' skip file End Select Next ' set the starting position to 0 ' and call the set images method ' to load the pictures mImagePosition = 0 SetImages() End If End Sub ''' <summary> ''' This function is used to set the previous, ''' current, and next images into the ''' correct picture boxes ''' </summary> ''' <remarks></remarks> Private Sub SetImages() ' clear any existing images ' memory will be an issue if ' cycling through a large ' number of images mPreviousImage = Nothing mNextImage = Nothing mCurrentImage = Nothing ' set the previous image If mImagePosition > 0 Then Try ' set delegate Dim prevCallback As Image.GetThumbnailImageAbort = _ New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ' get the previous image Dim prevBmp As _ New Bitmap(mImageList(mImagePosition - 1).ToString()) ' thumbnail the image to the size ' of the picture box mPreviousImage = _ prevBmp.GetThumbnailImage(160, 100, _ prevCallback, IntPtr.Zero) ' set the picture box image picPreviousImage.Image = mPreviousImage ' clear everything out prevBmp = Nothing prevCallback = Nothing mPreviousImage = Nothing Catch 'stall if it hangs, the user can retry End Try Else ' at the limit clear the ' image picPreviousImage.Image = Nothing End If ' set current image If mImagePosition < mImageList.Count Then Try ' set delegate Dim currentCallback = _ New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ' get the current image Dim currentBmp As _ New Bitmap(mImageList(mImagePosition).ToString()) ' thumbnail the image to the size ' of the picture box mCurrentImage = _ currentBmp.GetThumbnailImage(320, 200, currentCallback, IntPtr.Zero) ' set the picture box image picCurrentImage.Image = mCurrentImage ' clear everything out currentBmp = Nothing mCurrentImage = Nothing currentCallback = Nothing Catch 'stall if it hangs, the user can retry End Try End If ' set next image If mImagePosition < mImageList.Count - 1 Then Try ' set delegate Dim nextCallback As _ New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ' get the next image Dim nextBmp As _ New Bitmap(mImageList(mImagePosition 1).ToString()) ' thumbnail the image to the size ' of the picture box mNextImage = _ nextBmp.GetThumbnailImage(160, 100, nextCallback, IntPtr.Zero) ' set the picture box image picNextImage.Image = mNextImage ' clear everything out nextBmp = Nothing nextCallback = Nothing mNextImage = Nothing Catch 'stall if it hangs, the user can retry End Try Else ' at the limit clear the ' image picNextImage.Image = Nothing End If ' call for garbage collection GC.Collect() End Sub ''' <summary> ''' Thumbnail image abort target ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Public Function ThumbnailCallback() As Boolean Return False End Function ''' <summary> ''' Set the image position and reset all ''' of the images when the previous image ''' button is clicked ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnPreviousImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousImage.Click If (mImagePosition >= 0 And Not picPreviousImage.Image Is Nothing) Then mImagePosition -= 1 SetImages() End If End Sub ''' <summary> ''' Set the image position and reset all ''' of the images when the next image ''' button is clicked ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnNextImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextImage.Click If (mImagePosition <= (mImageList.Count - 2)) Then mImagePosition = 1 SetImages() End If End Sub ''' <summary> ''' Open the current image using the default ''' program per the user's file associations ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnOpenImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenImage.Click System.Diagnostics.Process.Start(mImageList(mImagePosition).ToString()) End SubEnd Class

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复